.TH std::reverse_iterator::operator++,+,+=,--,-,-= 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::reverse_iterator::operator++,+,+=,--,-,-= \- std::reverse_iterator::operator++,+,+=,--,-,-=

.SH Synopsis
   reverse_iterator&          (until
   operator++();              C++17)
   constexpr                  (since
   reverse_iterator&          C++17)
   operator++();
   reverse_iterator&                  (until
   operator--();                      C++17)
   constexpr                          (since
   reverse_iterator&                  C++17)
   operator--();
   reverse_iterator                           (until
   operator++( int );                         C++17)
   constexpr                                  (since
   reverse_iterator                           C++17)
   operator++( int );
   reverse_iterator                                  (until
   operator--( int );                                C++17)
   constexpr                                         (since
   reverse_iterator                                  C++17)
   operator--( int );
   reverse_iterator
   operator+(                                               (until
   difference_type n                                        C++17)
   ) const;
   constexpr
   reverse_iterator                                         (since
   operator+(                                               C++17)
   difference_type n  \fB(1)\fP
   ) const;
   reverse_iterator
   operator-(             \fB(2)\fP                                      (until
   difference_type n                                               C++17)
   ) const;                   \fB(3)\fP
   constexpr
   reverse_iterator                                                (since
   operator-(                         \fB(4)\fP                          C++17)
   difference_type n
   ) const;                                   \fB(5)\fP
   reverse_iterator&
   operator+=(                                                            (until
   difference_type n                                                      C++17)
   );
   constexpr                                         \fB(6)\fP
   reverse_iterator&                                                      (since
   operator+=(                                                            C++17)
   difference_type n
   );                                                       \fB(7)\fP
   reverse_iterator&
   operator-=(                                                                   (until
   difference_type n                                                             C++17)
   );
   constexpr                                                       \fB(8)\fP
   reverse_iterator&                                                             (since
   operator-=(                                                                   C++17)
   difference_type n
   );

   Increments or decrements the iterator. Inverse operations are applied to the
   underlying operator because of the reverse order.

   1,2) Pre-increments or pre-decrements by one respectively.
   3,4) Post-increments or post-decrements by one respectively.
   5,6) Returns an iterator which is advanced by n or -n positions respectively.
   7,8) Advances the iterator by n or -n positions respectively.

.SH Parameters

   n - position relative to current location

.SH Return value

   1,2) *this
   3,4) A copy of *this that was made before the change.
   5,6) reverse_iterator(base()-n) or reverse_iterator(base()+n) respectively.
   7,8) *this

.SH Example


// Run this code

 #include <iostream>
 #include <iterator>
 #include <list>
 #include <vector>

 int main()
 {
     std::vector v{0, 1, 2, 3, 4};
     auto rv = std::reverse_iterator{v.rbegin()};
     std::cout << *(++rv) << ' '; // 3
     std::cout << *(--rv) << ' '; // 4
     std::cout << *(rv + 3) << ' '; // 1
     rv += 3;
     std::cout << rv[0] << ' '; // 1
     rv -= 3;
     std::cout << rv[0] << '\\n'; // 4

     std::list l{5, 6, 7, 8};
     auto rl = std::reverse_iterator{l.rbegin()};
     std::cout << *(++rl) << ' '; // OK: 3
     std::cout << *(--rl) << '\\n'; // OK: 4
     // The following statements raise compilation error because the
     // underlying iterator does not model the random access iterator:
 //  *(rl + 3) = 13;
 //  rl += 3;
 //  rl -= 3;
 }

.SH Output:

 3 4 1 1 4
 7 8

.SH See also

   operator+ advances the iterator
             \fI(function template)\fP
   operator- computes the distance between two iterator adaptors
             \fI(function template)\fP
